package com.aim.analysis.records;

import com.aim.analysis.questionnaire.QuestionnaireRecord;
import com.aim.util.extractors.ValueExtractor;

/**
 * User: Avraham Shvartzon
 * Date: 9/12/14
 */
public class HitWrapperExtractor<A,V> extends ValueExtractor<Hit,V> {

    private ValueExtractor<Hit,A> adapter;
    ValueExtractor<A,V> extractor;

    public HitWrapperExtractor(ValueExtractor<Hit,A> adapter, ValueExtractor<A,V> extractor) {
        this(extractor.getName(),adapter, extractor);
    }

    public HitWrapperExtractor(String name, ValueExtractor<Hit,A> adapter, ValueExtractor<A,V> extractor) {
        super(name);
        this.adapter = adapter;
        this.extractor = extractor;
    }

    @Override
    public V getValue(Hit hit) {
        return extractor.getValue(adapter.getValue(hit));
    }

    public static final HitValueExtractor<QuestionnaireRecord> qAdapter = new HitValueExtractor<QuestionnaireRecord>("") {
        @Override
        public QuestionnaireRecord getValue(Hit hit) {
            return hit.questionnaireRecord;
        }
    };

    public static final HitValueExtractor<Game> alertGameAdapter = new HitValueExtractor<Game>("") {
        @Override
        public Game getValue(Hit hit) {
            return gameWithAlert.getValue(hit);
        }
    };

    public static final HitValueExtractor<Game> woAlertGameAdapter = new HitValueExtractor<Game>("") {
        @Override
        public Game getValue(Hit hit) {
            return gameWithoutAlert.getValue(hit);
        }
    };


}
